package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.cqgas.ds.dao.toll.example.TollGasUserDao;
import com.hzhr.iot.cqgas.ds.entity.toll.TollGasUserEntity;
import com.hzhr.iot.cqgas.ds.entity.toll.TollGasUserExample;
import com.hzhr.iot.cqgas.ds.service.GasUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GasUserController {
    @Autowired
    GasUserService gasUserService;
    @Autowired
    TollGasUserDao tollGasUserDao;

    @RequestMapping(value = "/syncGasUser")
    public void syncGasUser() {
        TollGasUserEntity tollGasUserEntity = new TollGasUserEntity();
        tollGasUserEntity.setState("3");
        TollGasUserExample tollGasUserExample = new TollGasUserExample();
        tollGasUserExample.createCriteria().andOutIdIsNotNull();
        tollGasUserDao.updateByExampleSelective(tollGasUserEntity, tollGasUserExample);

        gasUserService.syncGasUser(null, null);

        tollGasUserExample = new TollGasUserExample();
        tollGasUserExample.createCriteria().andStateEqualTo("3");
        tollGasUserDao.deleteByExample(tollGasUserExample);
    }

    @RequestMapping(value = "/syncGasUser_day")
    public void syncGasUser_day() {
        TollGasUserEntity tollGasUserEntity = new TollGasUserEntity();
        tollGasUserEntity.setState("3");
        TollGasUserExample tollGasUserExample = new TollGasUserExample();
        tollGasUserExample.createCriteria().andOutIdIsNotNull();
        tollGasUserDao.updateByExampleSelective(tollGasUserEntity, tollGasUserExample);

        gasUserService.syncGasUser(HzhrDateUtil.getDayBegin(), null);

        tollGasUserExample = new TollGasUserExample();
        tollGasUserExample.createCriteria().andStateEqualTo("3");
        tollGasUserDao.deleteByExample(tollGasUserExample);
    }

    @RequestMapping(value = "/syncGasUserGasConsumeAndDeviceCount")
    public void syncGasUserGasConsumeAndDeviceCount() {
        gasUserService.syncGasUserGasConsumeAndDeviceCount();
    }
}
